package com.elontian.util;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

public class IOUtil {

	// ��ȡ���ӷ��ص����
	public static byte[] readStream(InputStream inputStream) throws Exception {
		ByteArrayOutputStream baos = null;
		byte[] data = null;
		try {
			byte[] buffer = new byte[1024];
			int len = -1;
			baos = new ByteArrayOutputStream();
			while ((len = inputStream.read(buffer)) != -1) {
				baos.write(buffer, 0, len);
			}
			data = baos.toByteArray();
		} catch (Exception e) {
			// TODO: handle exception

			if (inputStream != null) {
				inputStream.close();
			}
			if (baos != null) {
				baos.close();
			}

		} finally {
			if (inputStream != null) {
				inputStream.close();
			}
			if (baos != null) {
				baos.close();
			}
		}

		return data;
	}

}
